/***********************************************************************
*                                                                      *
*               This software is part of the ast package               *
*          Copyright (c) 2003-2011 AT&T Intellectual Property          *
*                      and is licensed under the                       *
*                 Eclipse Public License, Version 1.0                  *
*                    by AT&T Intellectual Property                     *
*                                                                      *
*                A copy of the License is available at                 *
*          http://www.eclipse.org/org/documents/epl-v10.html           *
*         (with md5 checksum b35adb5213ca9657e911e9befb180842)         *
*                                                                      *
*              Information and Software Systems Research               *
*                            AT&T Research                             *
*                           Florham Park NJ                            *
*                                                                      *
*                   Phong Vo <kpv@research.att.com>                    *
*                                                                      *
***********************************************************************/
#include	<vclib.h>

/*	Map bytes from one to another (e.g., the rot13 program).
**	If no mapping is specified, the identity map is used.
**	Various mappings between different types of EBCDIC and ASCII
**	are provided.
**
**	Written by Kiem-Phong Vo (kpv@research.att.com)
*/

static Vcchar_t A2E[] =
{	/* CC_ASCII=>CC_EBCDIC_E */
	0000,0001,0002,0003,0067,0055,0056,0057, 0026,0005,0045,0013,0014,0015,0016,0017,
	0020,0021,0022,0023,0074,0075,0062,0046, 0030,0031,0077,0047,0034,0035,0036,0037,
	0100,0132,0177,0173,0133,0154,0120,0175, 0115,0135,0134,0116,0153,0140,0113,0141,
	0360,0361,0362,0363,0364,0365,0366,0367, 0370,0371,0172,0136,0114,0176,0156,0157,
	0174,0301,0302,0303,0304,0305,0306,0307, 0310,0311,0321,0322,0323,0324,0325,0326,
	0327,0330,0331,0342,0343,0344,0345,0346, 0347,0350,0351,0255,0340,0275,0232,0155,
	0171,0201,0202,0203,0204,0205,0206,0207, 0210,0211,0221,0222,0223,0224,0225,0226,
	0227,0230,0231,0242,0243,0244,0245,0246, 0247,0250,0251,0300,0117,0320,0137,0007,
	0040,0041,0042,0043,0044,0025,0006,0027, 0050,0051,0052,0053,0054,0011,0012,0033,
	0060,0061,0032,0063,0064,0065,0066,0010, 0070,0071,0072,0073,0004,0024,0076,0341,
	0101,0102,0103,0104,0105,0106,0107,0110, 0111,0121,0122,0123,0124,0125,0126,0127,
	0130,0131,0142,0143,0144,0145,0146,0147, 0150,0151,0160,0161,0162,0163,0164,0165,
	0166,0167,0170,0200,0212,0213,0214,0215, 0216,0217,0220,0152,0233,0234,0235,0236,
	0237,0240,0252,0253,0254,0112,0256,0257, 0260,0261,0262,0263,0264,0265,0266,0267,
	0270,0271,0272,0273,0274,0241,0276,0277, 0312,0313,0314,0315,0316,0317,0332,0333,
	0334,0335,0336,0337,0352,0353,0354,0355, 0356,0357,0372,0373,0374,0375,0376,0377
};

static Vcchar_t E2A[] =
{	/* CC_EBCDIC_E=>CC_ASCII */
	0000,0001,0002,0003,0234,0011,0206,0177, 0227,0215,0216,0013,0014,0015,0016,0017,
	0020,0021,0022,0023,0235,0205,0010,0207, 0030,0031,0222,0217,0034,0035,0036,0037,
	0200,0201,0202,0203,0204,0012,0027,0033, 0210,0211,0212,0213,0214,0005,0006,0007,
	0220,0221,0026,0223,0224,0225,0226,0004, 0230,0231,0232,0233,0024,0025,0236,0032,
	0040,0240,0241,0242,0243,0244,0245,0246, 0247,0250,0325,0056,0074,0050,0053,0174,
	0046,0251,0252,0253,0254,0255,0256,0257, 0260,0261,0041,0044,0052,0051,0073,0176,
	0055,0057,0262,0263,0264,0265,0266,0267, 0270,0271,0313,0054,0045,0137,0076,0077,
	0272,0273,0274,0275,0276,0277,0300,0301, 0302,0140,0072,0043,0100,0047,0075,0042,
	0303,0141,0142,0143,0144,0145,0146,0147, 0150,0151,0304,0305,0306,0307,0310,0311,
	0312,0152,0153,0154,0155,0156,0157,0160, 0161,0162,0136,0314,0315,0316,0317,0320,
	0321,0345,0163,0164,0165,0166,0167,0170, 0171,0172,0322,0323,0324,0133,0326,0327,
	0330,0331,0332,0333,0334,0335,0336,0337, 0340,0341,0342,0343,0344,0135,0346,0347,
	0173,0101,0102,0103,0104,0105,0106,0107, 0110,0111,0350,0351,0352,0353,0354,0355,
	0175,0112,0113,0114,0115,0116,0117,0120, 0121,0122,0356,0357,0360,0361,0362,0363,
	0134,0237,0123,0124,0125,0126,0127,0130, 0131,0132,0364,0365,0366,0367,0370,0371,
	0060,0061,0062,0063,0064,0065,0066,0067, 0070,0071,0372,0373,0374,0375,0376,0377
};

static Vcchar_t	A2I[] =
{	/* CC_ASCII=>CC_EBCDIC_I */
	0000,0001,0002,0003,0067,0055,0056,0057, 0026,0005,0045,0013,0014,0015,0016,0017,
	0020,0021,0022,0023,0074,0075,0062,0046, 0030,0031,0077,0047,0034,0035,0036,0037,
	0100,0132,0177,0173,0133,0154,0120,0175, 0115,0135,0134,0116,0153,0140,0113,0141,
	0360,0361,0362,0363,0364,0365,0366,0367, 0370,0371,0172,0136,0114,0176,0156,0157,
	0174,0301,0302,0303,0304,0305,0306,0307, 0310,0311,0321,0322,0323,0324,0325,0326,
	0327,0330,0331,0342,0343,0344,0345,0346, 0347,0350,0351,0255,0340,0275,0137,0155,
	0171,0201,0202,0203,0204,0205,0206,0207, 0210,0211,0221,0222,0223,0224,0225,0226,
	0227,0230,0231,0242,0243,0244,0245,0246, 0247,0250,0251,0300,0117,0320,0241,0007,
	0040,0041,0042,0043,0044,0025,0006,0027, 0050,0051,0052,0053,0054,0011,0012,0033,
	0060,0061,0032,0063,0064,0065,0066,0010, 0070,0071,0072,0073,0004,0024,0076,0341,
	0101,0102,0103,0104,0105,0106,0107,0110, 0111,0121,0122,0123,0124,0125,0126,0127,
	0130,0131,0142,0143,0144,0145,0146,0147, 0150,0151,0160,0161,0162,0163,0164,0165,
	0166,0167,0170,0200,0212,0213,0214,0215, 0216,0217,0220,0232,0233,0234,0235,0236,
	0237,0240,0252,0253,0254,0255,0256,0257, 0260,0261,0262,0263,0264,0265,0266,0267,
	0270,0271,0272,0273,0274,0275,0276,0277, 0312,0313,0314,0315,0316,0317,0332,0333,
	0334,0335,0336,0337,0352,0353,0354,0355, 0356,0357,0372,0373,0374,0375,0376,0377
};

static Vcchar_t I2A[] =
{	/* CC_EBCDIC_I=>CC_ASCII */
	0000,0001,0002,0003,0234,0011,0206,0177, 0227,0215,0216,0013,0014,0015,0016,0017,
	0020,0021,0022,0023,0235,0205,0010,0207, 0030,0031,0222,0217,0034,0035,0036,0037,
	0200,0201,0202,0203,0204,0012,0027,0033, 0210,0211,0212,0213,0214,0005,0006,0007,
	0220,0221,0026,0223,0224,0225,0226,0004, 0230,0231,0232,0233,0024,0025,0236,0032,
	0040,0240,0241,0242,0243,0244,0245,0246, 0247,0250,0112,0056,0074,0050,0053,0174,
	0046,0251,0252,0253,0254,0255,0256,0257, 0260,0261,0041,0044,0052,0051,0073,0136,
	0055,0057,0262,0263,0264,0265,0266,0267, 0270,0271,0152,0054,0045,0137,0076,0077,
	0272,0273,0274,0275,0276,0277,0300,0301, 0302,0140,0072,0043,0100,0047,0075,0042,
	0303,0141,0142,0143,0144,0145,0146,0147, 0150,0151,0304,0305,0306,0307,0310,0311,
	0312,0152,0153,0154,0155,0156,0157,0160, 0161,0162,0313,0314,0315,0316,0317,0320,
	0321,0176,0163,0164,0165,0166,0167,0170, 0171,0172,0322,0323,0324,0133,0326,0327,
	0330,0331,0332,0333,0334,0335,0336,0337, 0340,0341,0342,0343,0344,0135,0346,0347,
	0173,0101,0102,0103,0104,0105,0106,0107, 0110,0111,0350,0351,0352,0353,0354,0355,
	0175,0112,0113,0114,0115,0116,0117,0120, 0121,0122,0356,0357,0360,0361,0362,0363,
	0134,0237,0123,0124,0125,0126,0127,0130, 0131,0132,0364,0365,0366,0367,0370,0371,
	0060,0061,0062,0063,0064,0065,0066,0067, 0070,0071,0372,0373,0374,0375,0376,0377
};

static Vcchar_t A2O[] =
{	/* CC_ASCII=>CC_EBDCID_O */
	0000,0001,0002,0003,0067,0055,0056,0057, 0026,0005,0025,0013,0014,0015,0016,0017,
	0020,0021,0022,0023,0074,0075,0062,0046, 0030,0031,0077,0047,0034,0035,0036,0037,
	0100,0132,0177,0173,0133,0154,0120,0175, 0115,0135,0134,0116,0153,0140,0113,0141,
	0360,0361,0362,0363,0364,0365,0366,0367, 0370,0371,0172,0136,0114,0176,0156,0157,
	0174,0301,0302,0303,0304,0305,0306,0307, 0310,0311,0321,0322,0323,0324,0325,0326,
	0327,0330,0331,0342,0343,0344,0345,0346, 0347,0350,0351,0255,0340,0275,0137,0155,
	0171,0201,0202,0203,0204,0205,0206,0207, 0210,0211,0221,0222,0223,0224,0225,0226,
	0227,0230,0231,0242,0243,0244,0245,0246, 0247,0250,0251,0300,0117,0320,0241,0007,
	0040,0041,0042,0043,0044,0045,0006,0027, 0050,0051,0052,0053,0054,0011,0012,0033,
	0060,0061,0032,0063,0064,0065,0066,0010, 0070,0071,0072,0073,0004,0024,0076,0377,
	0101,0252,0112,0261,0237,0262,0152,0265, 0273,0264,0232,0212,0260,0312,0257,0274,
	0220,0217,0352,0372,0276,0240,0266,0263, 0235,0332,0233,0213,0267,0270,0271,0253,
	0144,0145,0142,0146,0143,0147,0236,0150, 0164,0161,0162,0163,0170,0165,0166,0167,
	0254,0151,0355,0356,0353,0357,0354,0277, 0200,0375,0376,0373,0374,0272,0256,0131,
	0104,0105,0102,0106,0103,0107,0234,0110, 0124,0121,0122,0123,0130,0125,0126,0127,
	0214,0111,0315,0316,0313,0317,0314,0341, 0160,0335,0336,0333,0334,0215,0216,0337
};

static Vcchar_t O2A[] =
{	/* CC_EBDCID_O=>CC_ASCII */
	0000,0001,0002,0003,0234,0011,0206,0177, 0227,0215,0216,0013,0014,0015,0016,0017,
	0020,0021,0022,0023,0235,0012,0010,0207, 0030,0031,0222,0217,0034,0035,0036,0037,
	0200,0201,0202,0203,0204,0205,0027,0033, 0210,0211,0212,0213,0214,0005,0006,0007,
	0220,0221,0026,0223,0224,0225,0226,0004, 0230,0231,0232,0233,0024,0025,0236,0032,
	0040,0240,0342,0344,0340,0341,0343,0345, 0347,0361,0242,0056,0074,0050,0053,0174,
	0046,0351,0352,0353,0350,0355,0356,0357, 0354,0337,0041,0044,0052,0051,0073,0136,
	0055,0057,0302,0304,0300,0301,0303,0305, 0307,0321,0246,0054,0045,0137,0076,0077,
	0370,0311,0312,0313,0310,0315,0316,0317, 0314,0140,0072,0043,0100,0047,0075,0042,
	0330,0141,0142,0143,0144,0145,0146,0147, 0150,0151,0253,0273,0360,0375,0376,0261,
	0260,0152,0153,0154,0155,0156,0157,0160, 0161,0162,0252,0272,0346,0270,0306,0244,
	0265,0176,0163,0164,0165,0166,0167,0170, 0171,0172,0241,0277,0320,0133,0336,0256,
	0254,0243,0245,0267,0251,0247,0266,0274, 0275,0276,0335,0250,0257,0135,0264,0327,
	0173,0101,0102,0103,0104,0105,0106,0107, 0110,0111,0255,0364,0366,0362,0363,0365,
	0175,0112,0113,0114,0115,0116,0117,0120, 0121,0122,0271,0373,0374,0371,0372,0377,
	0134,0367,0123,0124,0125,0126,0127,0130, 0131,0132,0262,0324,0326,0322,0323,0325,
	0060,0061,0062,0063,0064,0065,0066,0067, 0070,0071,0263,0333,0334,0331,0332,0237
};

static Vcchar_t A2S[] =
{	/* CC_ASCII=>CC_EBCDIC_S */
	0000,0001,0002,0003,0067,0055,0056,0057, 0026,0005,0025,0013,0014,0015,0016,0017,
	0020,0021,0022,0023,0074,0075,0062,0046, 0030,0031,0077,0047,0034,0035,0036,0037,
	0100,0132,0177,0173,0133,0154,0120,0175, 0115,0135,0134,0116,0153,0140,0113,0141,
	0360,0361,0362,0363,0364,0365,0366,0367, 0370,0371,0172,0136,0114,0176,0156,0157,
	0174,0301,0302,0303,0304,0305,0306,0307, 0310,0311,0321,0322,0323,0324,0325,0326,
	0327,0330,0331,0342,0343,0344,0345,0346, 0347,0350,0351,0273,0274,0275,0152,0155,
	0112,0201,0202,0203,0204,0205,0206,0207, 0210,0211,0221,0222,0223,0224,0225,0226,
	0227,0230,0231,0242,0243,0244,0245,0246, 0247,0250,0251,0373,0117,0375,0377,0007,
	0040,0041,0042,0043,0044,0045,0006,0027, 0050,0051,0052,0053,0054,0011,0012,0033,
	0060,0061,0032,0063,0064,0065,0066,0010, 0070,0071,0072,0073,0004,0024,0076,0137,
	0101,0252,0260,0261,0237,0262,0320,0265, 0171,0264,0232,0212,0272,0312,0257,0241,
	0220,0217,0352,0372,0276,0240,0266,0263, 0235,0332,0233,0213,0267,0270,0271,0253,
	0144,0145,0142,0146,0143,0147,0236,0150, 0164,0161,0162,0163,0170,0165,0166,0167,
	0254,0151,0355,0356,0353,0357,0354,0277, 0200,0340,0376,0335,0374,0255,0256,0131,
	0104,0105,0102,0106,0103,0107,0234,0110, 0124,0121,0122,0123,0130,0125,0126,0127,
	0214,0111,0315,0316,0313,0317,0314,0341, 0160,0300,0336,0333,0334,0215,0216,0337
};

static Vcchar_t	S2A[] =
{	/* CC_EBCDIC_S=>CC_ASCII */
	0000,0001,0002,0003,0234,0011,0206,0177, 0227,0215,0216,0013,0014,0015,0016,0017,
	0020,0021,0022,0023,0235,0012,0010,0207, 0030,0031,0222,0217,0034,0035,0036,0037,
	0200,0201,0202,0203,0204,0205,0027,0033, 0210,0211,0212,0213,0214,0005,0006,0007,
	0220,0221,0026,0223,0224,0225,0226,0004, 0230,0231,0232,0233,0024,0025,0236,0032,
	0040,0240,0342,0344,0340,0341,0343,0345, 0347,0361,0140,0056,0074,0050,0053,0174,
	0046,0351,0352,0353,0350,0355,0356,0357, 0354,0337,0041,0044,0052,0051,0073,0237,
	0055,0057,0302,0304,0300,0301,0303,0305, 0307,0321,0136,0054,0045,0137,0076,0077,
	0370,0311,0312,0313,0310,0315,0316,0317, 0314,0250,0072,0043,0100,0047,0075,0042,
	0330,0141,0142,0143,0144,0145,0146,0147, 0150,0151,0253,0273,0360,0375,0376,0261,
	0260,0152,0153,0154,0155,0156,0157,0160, 0161,0162,0252,0272,0346,0270,0306,0244,
	0265,0257,0163,0164,0165,0166,0167,0170, 0171,0172,0241,0277,0320,0335,0336,0256,
	0242,0243,0245,0267,0251,0247,0266,0274, 0275,0276,0254,0133,0134,0135,0264,0327,
	0371,0101,0102,0103,0104,0105,0106,0107, 0110,0111,0255,0364,0366,0362,0363,0365,
	0246,0112,0113,0114,0115,0116,0117,0120, 0121,0122,0271,0373,0374,0333,0372,0377,
	0331,0367,0123,0124,0125,0126,0127,0130, 0131,0132,0262,0324,0326,0322,0323,0325,
	0060,0061,0062,0063,0064,0065,0066,0067, 0070,0071,0263,0173,0334,0175,0332,0176
};

static Vcchar_t	A2H[] =
{	/* CC_ASCII=>CC_EBCDIC_H */
	0000,0001,0002,0003,0067,0055,0056,0057, 0026,0005,0045,0013,0014,0015,0016,0017,
	0020,0021,0022,0023,0074,0075,0062,0046, 0030,0031,0077,0047,0034,0035,0036,0037,
	0100,0132,0177,0173,0133,0154,0120,0175, 0115,0135,0134,0116,0153,0140,0113,0141,
	0360,0361,0362,0363,0364,0365,0366,0367, 0370,0371,0172,0136,0114,0176,0156,0157,
	0174,0301,0302,0303,0304,0305,0306,0307, 0310,0311,0321,0322,0323,0324,0325,0326,
	0327,0330,0331,0342,0343,0344,0345,0346, 0347,0350,0351,0272,0340,0273,0260,0155,
	0171,0201,0202,0203,0204,0205,0206,0207, 0210,0211,0221,0222,0223,0224,0225,0226,
	0227,0230,0231,0242,0243,0244,0245,0246, 0247,0250,0251,0300,0117,0320,0241,0007,
	0040,0041,0042,0043,0044,0025,0006,0027, 0050,0051,0052,0053,0054,0011,0012,0033,
	0060,0061,0032,0063,0064,0065,0066,0010, 0070,0071,0072,0073,0004,0024,0076,0377,
	0101,0252,0112,0261,0237,0262,0152,0265, 0275,0264,0232,0212,0137,0312,0257,0274,
	0220,0217,0352,0372,0276,0240,0266,0263, 0235,0332,0233,0213,0267,0270,0271,0253,
	0144,0145,0142,0146,0143,0147,0236,0150, 0164,0161,0162,0163,0170,0165,0166,0167,
	0254,0151,0355,0356,0353,0357,0354,0277, 0200,0375,0376,0373,0374,0255,0256,0131,
	0104,0105,0102,0106,0103,0107,0234,0110, 0124,0121,0122,0123,0130,0125,0126,0127,
	0214,0111,0315,0316,0313,0317,0314,0341, 0160,0335,0336,0333,0334,0215,0216,0337
};

static Vcchar_t	H2A[] =
{	/* CC_EBCDIC_H=>CC_ASCII */
	0000,0001,0002,0003,0234,0011,0206,0177, 0227,0215,0216,0013,0014,0015,0016,0017,
	0020,0021,0022,0023,0235,0205,0010,0207, 0030,0031,0222,0217,0034,0035,0036,0037,
	0200,0201,0202,0203,0204,0012,0027,0033, 0210,0211,0212,0213,0214,0005,0006,0007,
	0220,0221,0026,0223,0224,0225,0226,0004, 0230,0231,0232,0233,0024,0025,0236,0032,
	0040,0240,0342,0344,0340,0341,0343,0345, 0347,0361,0242,0056,0074,0050,0053,0174,
	0046,0351,0352,0353,0350,0355,0356,0357, 0354,0337,0041,0044,0052,0051,0073,0254,
	0055,0057,0302,0304,0300,0301,0303,0305, 0307,0321,0246,0054,0045,0137,0076,0077,
	0370,0311,0312,0313,0310,0315,0316,0317, 0314,0140,0072,0043,0100,0047,0075,0042,
	0330,0141,0142,0143,0144,0145,0146,0147, 0150,0151,0253,0273,0360,0375,0376,0261,
	0260,0152,0153,0154,0155,0156,0157,0160, 0161,0162,0252,0272,0346,0270,0306,0244,
	0265,0176,0163,0164,0165,0166,0167,0170, 0171,0172,0241,0277,0320,0335,0336,0256,
	0136,0243,0245,0267,0251,0247,0266,0274, 0275,0276,0133,0135,0257,0250,0264,0327,
	0173,0101,0102,0103,0104,0105,0106,0107, 0110,0111,0255,0364,0366,0362,0363,0365,
	0175,0112,0113,0114,0115,0116,0117,0120, 0121,0122,0271,0373,0374,0371,0372,0377,
	0134,0367,0123,0124,0125,0126,0127,0130, 0131,0132,0262,0324,0326,0322,0323,0325,
	0060,0061,0062,0063,0064,0065,0066,0067, 0070,0071,0263,0333,0334,0331,0332,0237
};

static Vcmtarg_t _Mapargs[] =
{	{ "a2e", "ASCII -> Xopen dd(1) EBCDIC.", A2E },
	{ "e2a", "Xopen dd(1) EBCDIC -> ASCII.", E2A },
	{ "a2i", "ASCII -> Xopen dd(1) IBM.", A2I },
	{ "i2a", "Xopen dd(1) IBM -> ASCII.", I2A },
	{ "a2o", "ASCII -> IBM OpenEdition.", A2O },
	{ "o2a", "IBM OpenEdition -> ASCII.", O2A },
	{ "a2s", "ASCII -> Siemens Posix-bc.", A2S },
	{ "s2a", "Siemens Posix-bc -> ASCII.", S2A },
	{ "a2h", "ASCII -> IBM-37 AS/400.", A2H },
	{ "h2a", "IBM-37 AS/400 -> ASCII.", H2A },
	{   0  , "Identity mapping.", 0 }
};

typedef struct _vcmap_s
{	Vcchar_t*	map;
} Vcmap_t;

#if __STD_C
static ssize_t vcmap(Vcodex_t* vc, const Void_t* data, size_t size, Void_t** out)
#else
static ssize_t vcmap(vc, data, size, out)
Vcodex_t*	vc;
Void_t*		data;
size_t		size;
Void_t**	out;
#endif
{
	ssize_t		sz;
	Vcchar_t	*dt, *enddt, *output, *o;
	Vcchar_t	*map;
	Vcmap_t		*vcm = vcgetmtdata(vc, Vcmap_t*);
	Vcdisc_t	*disc = vcgetdisc(vc);

	if((sz = (ssize_t)size) == 0)
		return 0;
	if(!(dt = (Vcchar_t*)data) )
		return -1;

	if(!(map = vcm->map) )
		if(disc && disc->data)
			map = disc->data;

	if(vc->flags&VC_DECODE)
		if(vcrecode(vc, &dt, &sz, 0, 0) < 0)
			return -1;

	if(!(output = vcbuffer(vc, NIL(Vcchar_t*), sz, 0)) )
		return -1;

	if(!map)
		memcpy(output, dt, sz);
	else for(o = output, enddt = dt+sz; dt < enddt; )
		*o++ = map[*dt++];

	if((vc->flags&VC_DECODE) && vc->coder)
		vcbuffer(vc, dt-sz, -1, -1);

	if(vc->flags&VC_ENCODE)
	{	dt = output;
		if(vcrecode(vc, &output, &sz, 0, 0) < 0 )
			return -1;
		if(dt != output)
			vcbuffer(vc, dt, -1, -1);
	}

	if(out)
		*out = output;
	return sz;
}

#if __STD_C
static int mapevent(Vcodex_t* vc, int type, Void_t* params)
#else
static int mapevent(vc, type, params)
Vcodex_t*	vc;
int		type;
Void_t*		params;
#endif
{
	Vcmap_t		*vcm;
	Vcmtarg_t	*arg;

	if(type == VC_OPENING)
	{	if(!(vcm = (Vcmap_t*)calloc(1, sizeof(Vcmap_t))) )
			return -1;

		if(params) /* get the mapping type, if any */
		{	vcgetmtarg((char*)params, 0, 0, _Mapargs, &arg);
			if(arg)
				vcm->map = arg->data;
		}

		vcsetmtdata(vc, vcm);
	}
	else if(type == VC_CLOSING)
	{	if((vcm = vcgetmtdata(vc, Vcmap_t*)) )
			free(vcm);
		vcsetmtdata(vc, NIL(Vcmap_t*));
	}

	return 0;
}

Vcmethod_t _Vcmap =
{	vcmap,
	vcmap,
	mapevent,
	"map", "Mapping bytes from codeset to codeset.",
	"[-version?map (AT&T Research) 2003-01-01]" USAGE_LICENSE,
	_Mapargs,
	1024*1024,
	0
};

VCLIB(Vcmap)
